#ifndef GAME_
#define GAME_

#include <iostream>
#include <string>
#include <SDL.h>
#include <SDL_image.h>
#include <vector>
#include "log.h"
#include "texture_manager.h"
#include "input_handler.h"
#include "game_object.h"
#include "player.h"
#include "enemy.h"
#include "menu_button.h"
#include "main_menu_state.h"
#include "play_state.h"
#include "pause_state.h"
#include "game_over_state.h"
#include "game_state_machine.h"
#include "game_object_factory.h"

class Game {
public:
    bool Init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
    void HandleEvents();
    void Update();
    void Render();
    void Clean();
    inline bool Running() {return is_running_;}
    void Quit() {is_running_ = false;}
    void Flip() {is_flip_ = true;}
    void NonFlip() {is_flip_ = false;}
    SDL_Renderer* get_renderer() const {return renderer_;}
    GameStateMachine* get_state_machine() { return game_state_machine_; }

    // singleton. Do not try to delete(free) singleton!!
    static Game& instance() {
        static Game game_instance;
        return game_instance;
    }

private:
    Game();  // singleton
    ~Game();

    SDL_Window* window_;
    SDL_Renderer* renderer_;

    int speed_ = 1;
    bool is_flip_ = false;
    int current_frame_ = 0;
    bool is_running_;

    std::vector<GameObject*> gameobjects_;
    GameObject* go_;
    GameObject* player_;
    GameObject* enemy_;

    GameStateMachine* game_state_machine_;
};

typedef Game TheGame;

#endif // GAME_
